﻿@using System.Text;
@using WebMatrix.Data;
@using System.Globalization;
@{
           var service = UrlData[0].ToLower();;
           var id = UrlData[1];
           
           // 
        
           //get form elements
           
            Customer c = new Customer();
            c.CustomerClassification=UtilityManager.GetVal(Request["custClass"]);
            c.CustomerStatus=UtilityManager.GetVal(Request["custStatus"]);
            c.Region=UtilityManager.GetVal(Request["region"]);
            c.Solicitor=UtilityManager.GetVal(Request["solicitor"]);
            c.Campaign=UtilityManager.GetVal(Request["campaign"]);
            //c.ReferredBy=UtilityManager.GetVal(Request["refBy"]);
            c.ReferredBy=UtilityManager.GetVal(Request["rByid"]);           
            c.RelationshipToReferror=UtilityManager.GetVal(Request["rel2ref"]);
            c.Country=UtilityManager.GetVal(Request["country"]);
            c.FName=UtilityManager.GetVal(Request["fname"]);
            c.MName=UtilityManager.GetVal(Request["mname"]);
            c.LName=UtilityManager.GetVal(Request["lname"]);
            c.Gender=UtilityManager.GetVal(Request["gender"]);
            c.MonthArrived=UtilityManager.GetVal(Request["monArr"]);
            c.Nationality=UtilityManager.GetVal(Request["nationality"]);
            var bdate = Request["bdate"];
            
            c.Bdate=UtilityManager.GetDateVal(bdate);
            c.PlaceOfBirth=UtilityManager.GetVal(Request["pob"]);
            c.MotherMName=UtilityManager.GetVal(Request["mMName"]);
            c.CivilStatus=UtilityManager.GetVal(Request["civilStatus"]);
            c.IDNumber=UtilityManager.GetVal(Request["idNo"]);
            c.IDType=UtilityManager.GetVal(Request["idType"]);
            c.Email=UtilityManager.GetVal(Request["email"]);
            c.CurrMailAdd=UtilityManager.GetVal(Request["currMailAdd1"]) +"|"+ UtilityManager.GetVal(Request["currMailAdd2"]);
            c.CurrMailCity=UtilityManager.GetVal(Request["currMailCity"]);
            c.CurrMailState=UtilityManager.GetVal(Request["currMailState"]);
            c.CurrMailCountry=UtilityManager.GetVal(Request["currMailCountry"]);
            c.CurrMailZip=UtilityManager.GetVal(Request["currMailZip"]);
            c.PermAdd=UtilityManager.GetVal(Request["permAdd1"])+"|" +UtilityManager.GetVal(Request["permAdd2"]);
            c.PermAddCity=UtilityManager.GetVal(Request["permAddCity"]);
            c.PermAddState=UtilityManager.GetVal(Request["permAddState"]);
            c.PermAddCountry=UtilityManager.GetVal(Request["permAddCountry"]);
            c.PermAddZip=UtilityManager.GetVal(Request["permAddZip"]);
            c.SrcOfFunds=UtilityManager.GetVal(Request["srcOfFunds"]);
            c.Employment=UtilityManager.GetVal(Request["employment"]);
            c.Designation=UtilityManager.GetVal(Request["desigRank"]);
            c.Employer=UtilityManager.GetVal(Request["busName"]);
            c.NatureOfWork=UtilityManager.GetVal(Request["natureOfWork"]);
            c.WorkPhone=UtilityManager.GetVal(Request["busPhoneCC"])+"|"+UtilityManager.GetVal(Request["busPhoneAC"])+"|"+UtilityManager.GetVal(Request["busPhoneNo"]);
            c.BusAdd=UtilityManager.GetVal(Request["busAdd1"])+"|"+UtilityManager.GetVal(Request["busAdd2"]);
            c.BusAddCity=UtilityManager.GetVal(Request["busAddCity"]);
            c.BusAddState=UtilityManager.GetVal(Request["busAddState"]);
            c.BusAddCountry=UtilityManager.GetVal(Request["busAddCountry"]);
            c.BusAddZip=UtilityManager.GetVal(Request["busAddZip"]);
            c.ModeOfRemit=UtilityManager.GetVal(Request["modeOfRemit"]);
            c.CallFrequency=UtilityManager.GetVal(Request["callFreq"]);
            c.CargoFrequency=UtilityManager.GetVal(Request["cargoFreq"]);
            c.RemitFrequency=UtilityManager.GetVal(Request["remitReq"]);
            c.ModeOfCall=UtilityManager.GetVal(Request["modeOfCall"]);
            c.AllowContact=UtilityManager.GetVal(Request["allowContact"]);
            c.PrefModeOfComm=UtilityManager.GetVal(Request["prefModeOfComm"]);
            c.PrefCallTime=UtilityManager.GetVal(Request["prefCallTime"]);
            c.PreffCallDay=UtilityManager.GetVal(Request["prefCallDay"]);
            c.YearArrived=UtilityManager.GetVal(Request["yrArr"]);
            c.MobileNo=UtilityManager.GetVal(Request["mobileCC"]) +"|"+ UtilityManager.GetVal(Request["mobileAC"]) +"|"+ UtilityManager.GetVal(Request["mobilePNo"]);
            c.LandLineNo=UtilityManager.GetVal(Request["landLineCC"]) +"|"+ UtilityManager.GetVal(Request["landLineAC"]) +"|"+ UtilityManager.GetVal(Request["landLinePNo"]);
            c.Notes=UtilityManager.GetVal(Request["notes"]);
            
            

             //Get Customer and Card status from AppConstants
            string customer_prospect = AppConstants.CUSTOMER_PROSPECT;
            string customer_active   = AppConstants.CUSTOMER_ACTIVE;
            string cashcard_active   = AppConstants.CASHCARD_ACTIVE;  
            string cashcard_far      = AppConstants.CASHCARD_FOR_ACT_REQUEST;
            string cashcard_ip       = AppConstants.CASHCARD_INPROCESS;
            string card_delivery_fd  = AppConstants.CARD_DELIVERY_FD;


        var data=new object[2];
        switch(service){
            case "search":
                 // var query = CustomerManager.SearchCustomer(c);
                  int count = CustomerManager.CheckDuplicate(c);
                  data[0]=count;
                  //data[1]=query;
                  break;
            case "save":
                     //log activity
                    string custID=Request["custId"];
                    var saveOption = Request["saveOption"];
                    var userAction="";
                    c.HasDuplicate=Convert.ToInt32(Request["hasDup"]);
                    if(saveOption=="0" || saveOption=="1"){
                        //save Customer
                        if(custID==string.Empty){
                        custID = CustomerManager.GetNextCustomerID(Request["region"]);
                        }
                    
                        DateTime cdate = DateTime.Now;
                        c.CustomerID=custID;
                      
                        var cust =CustomerManager.GetCustomer(custID);
                        if(cust==null){
                            //add new customer
                                c.DateCreated=cdate;
                                c.DateUpdated=cdate;
                                CustomerManager.CreateCustomer(c); 
                                userAction="saveCustomer";
                                data[0]=CustomerManager.GetCustomer(c.CustomerID);
                            }else{
                                    //edit
                                    userAction="updateCustomer";
                                    c.DateUpdated=cdate;
                                    CustomerManager.UpdateCustomer(c); 
                                    data[0]=CustomerManager.GetCustomer(c.CustomerID);
                                }
                         
                    }
                    
                              //log changed values
                                var changedValues = Request["changeFormVal"];
                                if(changedValues!=null && changedValues!=""){
                                      string[] fel = changedValues.Split('|');
                                      foreach(var item in fel){
                                         string[] fe = item.Split(',');
                                         if(fe.Length>0){
                                              string cField=string.Empty;
                                              if(string.Compare(fe[0],"idNo")==0){
                                                   cField="IDNumber";
                                               }
                                               if(cField==string.Empty){
                                                   cField=fe[0];
                                               }
                                              AuditManager.Log(cField,userAction,fe[1],fe[2],@WebSecurity.CurrentUserName,c.CustomerID,"");
                                        }
                                       
                                        
                                    }
                                }
                   
                break;
            case "savecc":
                 //applyCashCard
                       //Customer Status = Prospect 
                        //get the next available cashcard app no. 
                        var customerID=UtilityManager.GetVal(Request["cID"]);
                        string ccAction=string.Empty;
                        
                        DateTime date = DateTime.Now;
                        CustomerCashCard cc = new CustomerCashCard();
                        //cc.CashCardAppNo=UtilityManager.GetVal(Request["ccId"]);
                        //cc.CashCardAppNo=cashCardAppNo;
                        cc.CustomerID=customerID;
                        cc.ApplicationDate=UtilityManager.GetDateVal(Request["appDate"]);
                        cc.CashCardStatus=UtilityManager.GetVal(Request["cashCardStatus"]);
                        cc.CashCardStatusDate=UtilityManager.GetDateVal(Request["ccStatusDate"]);
                        cc.DocumentStatus=UtilityManager.GetVal(Request["docStatus"]);
                        cc.CashCardNo=UtilityManager.GetVal(Request["txtCcNo"]);
                        cc.CashCardType=UtilityManager.GetVal(Request["cardType"]);
                        cc.PartnerBank=UtilityManager.GetVal(Request["partnerBnk"]);
                        //cc.StatusDate=UtilityManager.GetDateVal(Request["txtStatusDate"]);
                        cc.NameOnCard=UtilityManager.GetVal(Request["txtName"]);
                        cc.CardExpDate=UtilityManager.GetDateVal(Request["txtExpDate"]);
                        cc.CardDelStatus=UtilityManager.GetVal(Request["delStatus"]);
                        cc.DelStatusDate=UtilityManager.GetDateVal(Request["txtDelStatusDate"]);
                        cc.CardDelCourier=UtilityManager.GetVal(Request["Courier"]);
                        cc.Remarks=UtilityManager.GetVal(Request["remarks"]);
                        cc.DelRemarks=UtilityManager.GetVal(Request["dremarks"]);
                        cc.DelDate=UtilityManager.GetDateVal(Request["DelDate"]);
                          
                       //customer details
                       
                
                        Customer cDetails = new Customer();
                        cDetails.CustomerID=cc.CustomerID;
                        //cDetails.CustomerStatus="Prospect";
                        cDetails.CustomerStatus=customer_prospect; 
                        cDetails.SrcOfFunds = UtilityManager.GetVal(Request["ccsrcOfFunds"]);
                        cDetails.Employer = UtilityManager.GetVal(Request["ccbusName"]);
                        cDetails.NatureOfWork = UtilityManager.GetVal(Request["ccnatureOfWork"]);
                        cDetails.Bdate=UtilityManager.GetDateVal(Request["ccbdate"]);
                        cDetails.PlaceOfBirth=UtilityManager.GetVal(Request["ccpob"]);
                        cDetails.CivilStatus=UtilityManager.GetVal(Request["cc_civilStatus"]);
                        cDetails.IDType=UtilityManager.GetVal(Request["ccidType"]);
                        cDetails.IDNumber=UtilityManager.GetVal(Request["ccidNo"]);
                        cDetails.DateUpdated=date;
            
                        var result=new object();
                        if(id=="0"){
                            //save details in CustomerCashCard table
                            ccAction="newCashCard";
                             var cashCardAppNo=CustomerCashCard.GetNextCallCardID(customerID);
                             cc.CashCardAppNo=cashCardAppNo;
                             cc.DateCreated=date;
                             cc.DateUpdated=date;
                             result = CashCardManager.NewCashCardApp(cc);
                            //AuditManager.Log("saveCustomerCashCard","newCashCard","","",@WebSecurity.CurrentUserName);
                        }else{
                            //update cash card details
                            
                            //check if cash card status is ac (active)
                            if(String.Compare(cc.CashCardStatus,cashcard_active)==0){
                                //set Customer Status to active
                                //cDetails.CustomerStatus="Active";
                                cDetails.CustomerStatus=customer_active;
                            }
                            ccAction="updateCashCard";
                            cc.CashCardAppNo=UtilityManager.GetVal(Request["ccId"]);
                            cc.DateUpdated=date;
                            result=CashCardManager.UpdateCustomerCC(cc);
                            //AuditManager.Log("updateCustomerCashCard","updateCashCard","","",@WebSecurity.CurrentUserName);
                        } 
                        
                        //update Customer Details
                        CustomerManager.UpdateCustomerDetailsForCC(cDetails);
                        
                          //log changed values
                                var changedCCValues = Request["changeCCData"];
                                if(changedCCValues!=null ||changedCCValues!=""){
                                      string[] fel = changedCCValues.Split('|');
                                     
                                      foreach(var item in fel){
                                         string[] fe = item.Split(',');
                                         if(fe.Length>0){
                                               //map cashcard details
                                               string field=string.Empty;
                                               if(string.Compare(fe[0],"delStatus")==0){
                                                   field="CardDelStatus";
                                               }
                                               if(string.Compare(fe[0],"txtDelStatusDate")==0){
                                                   field="DelStatusDate";
                                               }
                                                if(string.Compare(fe[0],"dremarks")==0){
                                                   field="DelRemarks";
                                               }
                                                if(string.Compare(fe[0],"remarks")==0){
                                                   field="Remarks";
                                               }
                                                if(string.Compare(fe[0],"delStatus")==0){
                                                   field="CardDelStatus";
                                               }
                                                if(string.Compare(fe[0],"ccStatusDate")==0){
                                                   field="CashCardStatusDate";
                                               }
                                                if(string.Compare(fe[0],"docStatus")==0){
                                                   field="DocumentStatus";
                                               }
                                                if(string.Compare(fe[0],"idNo")==0){
                                                   field="IDNumber";
                                               }
                                                if(string.Compare(fe[0],"cashCardStatus")==0){
                                                   field="CashCardStatus";
                                               }
                                                if(string.Compare(fe[0],"txtCcNo")==0){
                                                   field="CashCardNo";
                                               }
                                                if(string.Compare(fe[0],"txtExpDate")==0){
                                                   field="CashCardExpDate";
                                               }
                                               if(string.Compare(fe[0],"ccidType")==0){
                                                   field="IDType";
                                               }
                                               if(string.Compare(fe[0],"ccidNo")==0){
                                                   field="IDNumber";
                                               }
                                               if(string.Compare(fe[0],"idType")==0){
                                                   field="IDType";
                                               }


                                               if(field==string.Empty){
                                                   field=fe[0];
                                               }
                                               AuditManager.Log(field,ccAction,fe[1],fe[2],@WebSecurity.CurrentUserName,cDetails.CustomerID,cc.CashCardAppNo);
                                      
                                        }
                                        
                                    }
                                }
                        //data[0]= CustomerManager.GetCustomer(Request["cID"]);
                        //data[1]=CustomerManager.GetCustomerCashCards(Request["cID"]);
                        data[0]=result;
                       break;
            case "nextccid":
                var ccid=CustomerCashCard.GetNextCallCardID(id);
                data[0]=ccid;
                break;
            case "getcc":
                var ccdetail = CashCardManager.GetCashCardDetails(id);
                data[0]=ccdetail;
                break;
            case "upload":
                    string sheet=string.Empty;
                    string uploadPath=string.Empty;
                    string processPath=string.Empty;
                    bool isUpdated=false;
                    string message = string.Empty;
                    if(id.Equals("activation")){
                          sheet="Fns_Conv";
                          uploadPath="~/upload/Activation/";
                          processPath="~/Content/Activation/processed/";
                    }
                    
                    if(id.Equals("delivery")){
                          sheet="Delivery";
                          uploadPath="~/upload/Delivery/";
                          processPath="~/Content/Delivery/processed/";
                    }
                    
                    if(id.Equals("ccnos")){
                        sheet="Fns_Conv";
                        uploadPath="~/upload/CCNumbers/";
                        processPath="~/Content/CCNumbers/processed/";
                    }
                    
                     string filePath=string.Empty;
                     string testData=string.Empty;
                     int recProc=0;
                    List<Dictionary<string,string>> ccList=null;
                    Dictionary<string,Dictionary<string,string>> updateList=null;
                    try{
                        
                        filePath = UtilityManager.GetFileFromUploadDir(Server.MapPath(uploadPath));
                        //check if fileexists
                        if(UtilityManager.FileExists(filePath)){
                                //check type of upload and call method to extract data
                                if(id.Equals("activation") || id.Equals("ccnos")){
                                ccList = CashCardManager.ExtFromCIFXLS(filePath,sheet);    
                                }else{
                                ccList = CashCardManager.ExtFromDelXLS(filePath,sheet); 
                                }
                              
                                foreach(var d in ccList){
                                    
                                    string ccappno=d["CashCardAppNo"];  
                                    
                                    CustomerCashCard ccU=new CustomerCashCard();
                                    if(ccappno!=""){
                                      ccU = CashCardManager.GetCashCardDetails(ccappno);
                                      //increment no of records processed
                                       
                                    }
                                    if(ccU.CustomerID!=null){
                                     message+="\nCustomer ID:"+ccU.CustomerID;   
                                    var customerOld = CustomerManager.GetCustomer(ccU.CustomerID);
                                    Customer customerNew = new Customer();
                                    customerNew.CustomerID = customerOld.CustomerID;
                                    customerNew.Bdate = customerOld.Bdate;
                                    customerNew.PlaceOfBirth = customerOld.PlaceOfBirth;
                                    customerNew.CivilStatus = customerOld.CivilStatus;
                                    customerNew.IDType = customerOld.IDType;
                                    customerNew.IDNumber = customerOld.IDNumber;
                                    customerNew.CustomerStatus = customerOld.CustomerStatus;
                                    customerNew.SrcOfFunds=customerOld.SrcOfFunds;
                                    customerNew.Employer = customerOld.Employer;
                                    customerNew.NatureOfWork=customerOld.NatureOfWork;
                                    customerNew.DateUpdated = customerOld.DateUpdated; 
                                        
                                        
                                    //  @ObjectInfo.Print(ccU);  
                                    //set fields to upate based on id (activation,delivery,assign ccnumbers)
                                    //  if(ccU!=null){
                                    //message+="Ext Type:" + id;     
                                        if(String.Compare(id,"activation")==0){
                                              //  message+="Ext Type:" + id;
                                                updateList=new Dictionary<string,Dictionary<string,string>>();
                                                if(DateTime.Compare(Convert.ToDateTime(ccU.CashCardStatusDate.ToString()),DateTime.Now)!=0){
                                                   UtilityManager.AddChangeFields(updateList,"CashCardStatusDate",ccU.CashCardStatusDate.ToString(),DateTime.Now.ToString());
                                                } 
                                                ccU.CashCardStatusDate=DateTime.Now;
                                                //ccU.CashCardStatus="ac";
                                                if(string.Compare(ccU.CashCardStatus,cashcard_active)!=0){
                                                   UtilityManager.AddChangeFields(updateList,"CashCardStatus",ccU.CashCardStatus,cashcard_active);
                                                }
                                                ccU.CashCardStatus=cashcard_active;
                                                
                                                 if(string.Compare(customerNew.CustomerStatus,customer_active)!=0){
                                                   UtilityManager.AddChangeFields(updateList,"CustomerStatus",customerNew.CustomerStatus,customer_active);
                                                }
                                                customerNew.CustomerStatus=customer_active;
                                                   //update cashcardstatus date
                                                if(DateTime.Compare(Convert.ToDateTime(ccU.CashCardStatusDate.ToString()),Convert.ToDateTime(DateTime.Now.ToString()))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"CashCardStatusDate",ccU.CashCardStatusDate.ToString(),DateTime.Now.ToString());
                                                }
                                                ccU.CashCardStatusDate=DateTime.Now;
                                                //customerNew.CustomerStatus="Active";
                                                customerNew.DateUpdated=DateTime.Now;
                                                //update customer details
                                                CustomerManager.UpdateCustomerDetailsForCC(customerNew);
                                            }
                                            
                                            if(String.Compare(id,"delivery")==0){
                                               // message+="Remarks Value:" + d["Remarks"];  
                                                updateList=new Dictionary<string,Dictionary<string,string>>();
                                                bool isDate=false;
                                                try{
                                                string cds = d["DelStatus"];   
                                                if(string.Compare(ccU.CardDelStatus,cds.ToLower(new CultureInfo("en-US",false)))!=0){
                                                   UtilityManager.AddChangeFields(updateList,"CardDelStatus",ccU.CardDelStatus,cds.ToLower(new CultureInfo("en-US",false)));
                                                }
                                                   
                                                ccU.CardDelStatus=cds.ToLower(new CultureInfo("en-US",false));
                                                if(d["DelDate"]!=""){
                                                  if(DateTime.Compare(Convert.ToDateTime(ccU.DelDate.ToString()),Convert.ToDateTime(d["DelDate"]))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"DeliveryDate",ccU.DelDate.ToString(),d["DelDate"]);
                                                  }  
                                                  ccU.DelDate =Convert.ToDateTime(d["DelDate"]);    
                                                }     
                                                if(d["DelStatusDate"]!=""){
                                                  if(DateTime.Compare(Convert.ToDateTime(ccU.DelStatusDate.ToString()),Convert.ToDateTime(d["DelStatusDate"]))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"DeliveryStatusDate",ccU.DelStatusDate.ToString(),d["DelStatusDate"]);
                                                  }   
                                                  ccU.DelStatusDate = Convert.ToDateTime(d["DelStatusDate"]);    
                                                }else{
                                                  if(DateTime.Compare(Convert.ToDateTime(ccU.DelStatusDate.ToString()),Convert.ToDateTime(DateTime.Now.ToString()))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"DeliveryStatusDate",string.Empty,DateTime.Now.ToString());
                                                  }   
                                                  ccU.DelStatusDate = DateTime.Now;    
                                       
                                                }
                                                 
                                                //ccU.Remarks=d["Remarks"];
                                                 if(string.Compare(ccU.DelRemarks,d["Remarks"])!=0){
                                                     UtilityManager.AddChangeFields(updateList,"Remarks",ccU.DelRemarks,d["Remarks"]);
                                                  }   
                                                 
                                                ccU.DelRemarks=d["Remarks"];
                                                //ccU.CashCardStatus="far";
                                                  if(string.Compare(ccU.CashCardStatus,cashcard_far)!=0){
                                                     UtilityManager.AddChangeFields(updateList,"CashCardStatus",ccU.CashCardStatus,cashcard_far);
                                                  }   
                                               
                                                ccU.CashCardStatus=cashcard_far;
                                                //update cashcardstatus date
                                                if(DateTime.Compare(Convert.ToDateTime(ccU.CashCardStatusDate.ToString()),Convert.ToDateTime(DateTime.Now.ToString()))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"CashCardStatusDate",ccU.CashCardStatusDate.ToString(),DateTime.Now.ToString());
                                                }
                                                ccU.CashCardStatusDate=DateTime.Now;
                                                
                                                  if(string.Compare(customerNew.IDType,d["IDType"])!=0){
                                                     UtilityManager.AddChangeFields(updateList,"IDType",customerNew.IDType,d["IDType"]);
                                                  }   
                                               
                                                customerNew.IDType=d["IDType"];
                                                
                                                
                                                  if(string.Compare(customerNew.IDNumber,d["IDNumber"])!=0){
                                                     UtilityManager.AddChangeFields(updateList,"IDNumber",customerNew.IDNumber,d["IDNumber"]);
                                                  }
                                                
                                                customerNew.IDNumber=d["IDNumber"];
                                                
                                                 if(string.Compare( ccU.DocumentStatus,d["DocumentStatus"])!=0){
                                                     UtilityManager.AddChangeFields(updateList,"DocumentStatus",ccU.DocumentStatus,d["DocumentStatus"]);
                                                  }
                                                ccU.DocumentStatus=d["DocumentStatus"];
                                                //update customer details
                                                CustomerManager.UpdateCustomerDetailsForCC(customerNew);
                                                isDate=true;    
                                                }catch(Exception e){
                                                    
                                                    isDate=false;
                                                }
                                                
                                                
                                            }
                                            
                                            if(String.Compare(id,"ccnos")==0){
                                                 updateList=new Dictionary<string,Dictionary<string,string>>();
                                                if(string.Compare( ccU.CashCardNo,d["CashCardNo"])!=0){
                                                    UtilityManager.AddChangeFields(updateList,"CashCardNo",ccU.CashCardNo,d["CashCardNo"]);
                                                }
                                                ccU.CashCardNo = d["CashCardNo"];
                                                //ccU.CashCardStatus="ip";
                                                //ccU.CardDelStatus="fd";
                                                if(string.Compare( ccU.CashCardStatus,cashcard_ip)!=0){
                                                    UtilityManager.AddChangeFields(updateList,"CashCardStatus",ccU.CashCardStatus,cashcard_ip);
                                                }
                                                ccU.CashCardStatus=cashcard_ip;
                                                
                                                if(string.Compare( ccU.CardDelStatus,card_delivery_fd)!=0){
                                                    UtilityManager.AddChangeFields(updateList,"CardDelStatus",ccU.CardDelStatus,card_delivery_fd);
                                                }
                                                ccU.CardDelStatus=card_delivery_fd;
                                               /* if(DateTime.Compare(Convert.ToDateTime(ccU.CashCardStatusDate.ToString()),Convert.ToDateTime(DateTime.Now.ToString()))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"CashCardStatusDate",ccU.CashCardStatusDate.ToString(),DateTime.Now.ToString());
                                                }
                                                ccU.CashCardStatusDate = DateTime.Now;*/
                                                
                                                if(DateTime.Compare(Convert.ToDateTime(ccU.DelStatusDate.ToString()),Convert.ToDateTime(DateTime.Now.ToString()))!=0){
                                                     UtilityManager.AddChangeFields(updateList,"DelStatusDate",ccU.DelStatusDate.ToString(),DateTime.Now.ToString());
                                                }
                                                ccU.DelStatusDate=DateTime.Now;

                                                
                                            }
                                            ccU.DateUpdated = DateTime.Now;
                                            var r = CashCardManager.UpdateCustomerCC(ccU); 
                                    // }
                                            
                                    //loop through the list of updated fields and log them
                                    foreach(KeyValuePair<string,Dictionary<string,string>> pair1 in updateList){
                                         foreach(KeyValuePair<string,string> pair2 in pair1.Value){
                                             AuditManager.Log(pair1.Key,string.Format("{0} {1}",id,"upload"),pair2.Key,pair2.Value,@WebSecurity.CurrentUserName,ccU.CustomerID,ccappno);
                                        }
                                       
                                    }        
                                    
                                    isUpdated=true;
                                    //update no of records processed
                                    recProc++;        
                                }
                                
                               
                                }
                        }else{
                            isUpdated=false;
                            message="File does not exist.";
                        } 
                    }catch(NullReferenceException nre){
                        message="Incorrect file uploaded for upload type";
                        isUpdated=false;
                        
                    }catch(Exception e){
                        message = e.ToString();
                        isUpdated=false;
                    }
                    
                   
                    
                    
                    //after processing move the file
                    if(isUpdated){
                        FileInfo f = new FileInfo(filePath);
                        UtilityManager.MoveFile(filePath,Server.MapPath(processPath)+f.Name);
                        UtilityManager.DeleteFile(filePath);
                        data[0]=string.Format("Cash card(s) updated successfully.<br/>Total records processed:#{0}",recProc) ;
                        //data[0]=message;
                    }else{
                        if(UtilityManager.FileExists(filePath)){
                             UtilityManager.DeleteFile(filePath);
                        }
                       
                        data[0]=message;
                    }
                   
                break;
                case "referby":
                    var rBy = CustomerManager.GetAllCustomers();
                    StringBuilder sb = new StringBuilder();
                    int ctr=0;
                    List<dynamic> refList=new List<dynamic>();
                    foreach(var r in rBy){
                        var refBy= new {value=r.CustomerID,label=r.FName +" " +r.LName};
                        refList.Add(refBy);
                    }
                    
                    data[0]=refList;
                    break;
            case "getserverdate":
                  DateTime serverDate = DateTime.Now;
                  data[0] = serverDate.ToString("MM/dd/yyyy");
                 
                break;
                
            case "getcustomer":
                  var cancelData = CustomerManager.GetCustomer(id);
                  data[0]=cancelData;
                break;
            }
            
                      
             
             Json.Write(data,Response.Output);
    
}